{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "比如说现在有一家A公司，它的Debt-Equity Ratio是1.6，但是因为我们拿一家相似的公司C公司进行研究，这家相似的公司C公司的Debt-Equity ratio是1.4，因为这家相似公司是一家上市公司，每天有涨跌数据，于是我们可以通过回归的方法想其收益数据与大盘的收益数据进行回归，得出相似公司的β为1.5，假设边际税率为31%的情况下，现在A公司的β是多少呢？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\beta_{TargetCompany}=(1+（1-r_{tax}）\\frac{D_T}{E_T})\\times(\\frac{1}{1+(1-r_{tax})\\frac{D_C}{E_C}})\\times\\beta_{comparable}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.7629704984740591\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1.6052899287894205"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def calculate_target_company_beta(tax,Target_DE_ratio,Comparable_DE_ratio,Comparable_Beta):\n",
    "    Unlevered_Beta=Comparable_Beta/(1+(1-tax)*Comparable_DE_ratio)\n",
    "#     print(Unlevered_Beta)\n",
    "    Target_Beta=(1+(1-tax)*Target_DE_ratio)*Unlevered_Beta\n",
    "    return Target_Beta\n",
    "calculate_target_company_beta(0.31,1.6,1.4,1.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "0.8549019607843139"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def calculate_target_company_beta(tax,Target_DE_ratio,Comparable_DE_ratio,Comparable_Beta):\n",
    "    Unlevered_Beta=Comparable_Beta/(1+(1-tax)*Comparable_DE_ratio)\n",
    "#     print(Unlevered_Beta)\n",
    "    Target_Beta=(1+(1-tax)*Target_DE_ratio)*Unlevered_Beta\n",
    "    return Target_Beta\n",
    "calculate_target_company_beta(0,(49/51),60/40,1.09)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pandas'",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mModuleNotFoundError\u001B[0m                       Traceback (most recent call last)",
      "\u001B[0;32m<ipython-input-2-4df4c4d0c7e2>\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[0;32m----> 1\u001B[0;31m \u001B[0;32mimport\u001B[0m \u001B[0mpandas\u001B[0m \u001B[0;32mas\u001B[0m \u001B[0mpd\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      2\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      3\u001B[0m \u001B[0mdf\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mpd\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mread_csv\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'300.csv'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mModuleNotFoundError\u001B[0m: No module named 'pandas'"
     ]
    }
   ],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "pycharm-9607c1d0",
   "language": "python",
   "display_name": "PyCharm (sklearn)"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}